//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package gitlab_triger

import (
	"fmt"
	"testing"
)

const _PR_HOOK_DATA = `
{
  "object_kind": "merge_request",
  "event_type": "merge_request",
  "user": {
    "id": 1,
    "name": "Administrator",
    "username": "root",
    "avatar_url": "https://www.gravatar.com/avatar/b4b328dfb4d8a2743e6cb237b1b82b478b11a7e317528d9e8ebb1a1d6355c4a9?s=80&d=identicon",
    "email": "[REDACTED]"
  },
  "project": {
    "id": 1,
    "name": "test·",
    "description": null,
    "web_url": "http://09b00b609eb5/g1/test",
    "avatar_url": null,
    "git_ssh_url": "git@09b00b609eb5:g1/test.git",
    "git_http_url": "http://09b00b609eb5/g1/test.git",
    "namespace": "g1",
    "visibility_level": 0,
    "path_with_namespace": "g1/test",
    "default_branch": "master",
    "ci_config_path": null,
    "homepage": "http://09b00b609eb5/g1/test",
    "url": "git@09b00b609eb5:g1/test.git",
    "ssh_url": "git@09b00b609eb5:g1/test.git",
    "http_url": "http://09b00b609eb5/g1/test.git"
  },
  "object_attributes": {
    "assignee_id": null,
    "author_id": 1,
    "created_at": "2025-02-12 07:57:02 UTC",
    "description": "aaaaaa",
    "draft": false,
    "head_pipeline_id": 2,
    "id": 1,
    "iid": 1,
    "last_edited_at": null,
    "last_edited_by_id": null,
    "merge_commit_sha": null,
    "merge_error": null,
    "merge_params": {
    },
    "merge_status": "checking",
    "merge_user_id": null,
    "merge_when_pipeline_succeeds": false,
    "milestone_id": null,
    "source_branch": "master",
    "source_project_id": 2,
    "state_id": 1,
    "target_branch": "master",
    "target_project_id": 1,
    "time_estimate": 0,
    "title": "编辑main.go",
    "updated_at": "2025-02-12 07:57:05 UTC",
    "updated_by_id": null,
    "prepared_at": "2025-02-12 07:57:05 UTC",
    "assignee_ids": [

    ],
    "blocking_discussions_resolved": true,
    "detailed_merge_status": "checking",
    "first_contribution": true,
    "human_time_change": null,
    "human_time_estimate": null,
    "human_total_time_spent": null,
    "labels": [

    ],
    "last_commit": {
      "id": "b2b988026d81d37c81385529b83865cd41eef4a4",
      "message": "编辑main.go\n\n\naaaaaa\n",
      "title": "编辑main.go",
      "timestamp": "2025-02-12T07:56:52+00:00",
      "url": "http://09b00b609eb5/g1/test/-/commit/b2b988026d81d37c81385529b83865cd41eef4a4",
      "author": {
        "name": "Administrator",
        "email": "[REDACTED]"
      }
    },
    "reviewer_ids": [

    ],
    "source": {
      "id": 2,
      "name": "test2",
      "description": null,
      "web_url": "http://09b00b609eb5/g1/test-2",
      "avatar_url": null,
      "git_ssh_url": "git@09b00b609eb5:g1/test-2.git",
      "git_http_url": "http://09b00b609eb5/g1/test-2.git",
      "namespace": "g1",
      "visibility_level": 0,
      "path_with_namespace": "g1/test-2",
      "default_branch": "master",
      "ci_config_path": null,
      "homepage": "http://09b00b609eb5/g1/test-2",
      "url": "git@09b00b609eb5:g1/test-2.git",
      "ssh_url": "git@09b00b609eb5:g1/test-2.git",
      "http_url": "http://09b00b609eb5/g1/test-2.git"
    },
    "state": "opened",
    "target": {
      "id": 1,
      "name": "test·",
      "description": null,
      "web_url": "http://09b00b609eb5/g1/test",
      "avatar_url": null,
      "git_ssh_url": "git@09b00b609eb5:g1/test.git",
      "git_http_url": "http://09b00b609eb5/g1/test.git",
      "namespace": "g1",
      "visibility_level": 0,
      "path_with_namespace": "g1/test",
      "default_branch": "master",
      "ci_config_path": null,
      "homepage": "http://09b00b609eb5/g1/test",
      "url": "git@09b00b609eb5:g1/test.git",
      "ssh_url": "git@09b00b609eb5:g1/test.git",
      "http_url": "http://09b00b609eb5/g1/test.git"
    },
    "time_change": 0,
    "total_time_spent": 0,
    "url": "http://09b00b609eb5/g1/test/-/merge_requests/1",
    "work_in_progress": false,
    "action": "open"
  },
  "labels": [

  ],
  "changes": {
    "merge_status": {
      "previous": "preparing",
      "current": "checking"
    },
    "updated_at": {
      "previous": "2025-02-12 07:57:02 UTC",
      "current": "2025-02-12 07:57:05 UTC"
    },
    "prepared_at": {
      "previous": null,
      "current": "2025-02-12 07:57:05 UTC"
    }
  },
  "repository": {
    "name": "test·",
    "url": "git@09b00b609eb5:g1/test.git",
    "description": null,
    "homepage": "http://09b00b609eb5/g1/test"
  }
}
`

func TestExtractPrHookAttr(t *testing.T) {
	attrList, err := ExtractPrHookAttr([]byte(_PR_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
